import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.awt.SplashScreen;

public class CalendarWindow extends JFrame implements ActionListener,
        MouseListener, FocusListener {
    int year, month, day;
    CalendarMessage calendarMessage;
    CalendarPad calendarPad;
    NotePad notePad;
    JTextField showYear, showMonth;
    JTextField showDay[];
    CalendarImage calendarImage;
    String picturename;//图像名称；
    String getPicture_address;
    Clock clock;
    JButton nextYear, previousYear, nextMonth, previousMonth;
    JButton saveDailyRecord, deleteDailyRecord, readDailyRecord;
    File dir;
    Color backColor = Color.white;

    public CalendarWindow() {
        dir = new File("./dailyRecord");
        dir.mkdir();
        showDay = new JTextField[42];
        for (int i = 0; i < showDay.length; i++) {
            showDay[i] = new JTextField();
            showDay[i].setBackground(backColor);
            showDay[i].setLayout(new GridLayout(3, 3));
            showDay[i].addMouseListener(this);
            showDay[i].addFocusListener(this);
        }
        calendarMessage = new CalendarMessage();
        calendarPad = new CalendarPad();
        notePad = new NotePad();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH) + 1;
        day = calendar.get(Calendar.DAY_OF_MONTH);
        calendarMessage.setYear(year);
        calendarMessage.setMonth(month);
        calendarMessage.setDay(day);
        calendarPad.setCalendarMessage(calendarMessage);
        calendarPad.setShowDayTextField(showDay);
        notePad.setMessage(year, month, day);
        calendarPad.showMonthCalendar();
        doMark();
        calendarImage = new CalendarImage();
        picturename = getPicture_address();//
        calendarImage.setImageFile(new File(picturename));
        JMenuBar menuBar = new JMenuBar();
        JMenu menusetting = new JMenu();
        JMenuItem changepicture = new JMenuItem();
        menusetting.setText("图像");//设置标题
        changepicture.setText("更改图片背景");//设置标题
        //添加菜单条上去；
        menusetting.add(changepicture);
        menuBar.add(menusetting);
        setJMenuBar(menuBar);
        //注册监听器
        changepicture.addActionListener(this);
        clock = new Clock();
        JSplitPane splitV1 = new
                JSplitPane(JSplitPane.VERTICAL_SPLIT, calendarPad, calendarImage);
        JSplitPane splitV2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, notePad, clock);
        JSplitPane splitH = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitV1, splitV2);
        add(splitH, BorderLayout.CENTER);
        showYear = new JTextField("" + year, 6);
        showYear.setFont(new Font("TimesRoman", Font.BOLD, 12));
        showYear.setHorizontalAlignment(JTextField.CENTER);
        showMonth = new JTextField("" + month, 4);
        showMonth.setFont(new Font("TimesRoman", Font.BOLD, 12));
        showMonth.setHorizontalAlignment(JTextField.CENTER);
        nextYear = new JButton("下年");
        previousYear = new JButton("上年");
        nextMonth = new JButton("下月");
        previousMonth = new JButton("上月");
        nextYear.addActionListener(this);
        previousYear.addActionListener(this);
        nextMonth.addActionListener(this);
        previousMonth.addActionListener(this);
        showYear.addActionListener(this);
        JPanel north = new JPanel();
        north.add(previousYear);
        north.add(showYear);
        north.add(nextYear);
        north.add(previousMonth);
        north.add(showMonth);
        north.add(nextMonth);
        add(north, BorderLayout.NORTH);
        saveDailyRecord = new JButton("保存日志");
        deleteDailyRecord = new JButton("删除日志");
        readDailyRecord = new JButton("读取日志");
        saveDailyRecord.addActionListener(this);
        deleteDailyRecord.addActionListener(this);
        readDailyRecord.addActionListener(this);
        JPanel pSouth = new JPanel();
        pSouth.add(saveDailyRecord);
        pSouth.add(deleteDailyRecord);
        pSouth.add(readDailyRecord);
        add(pSouth, BorderLayout.SOUTH);
        setVisible(true);
        setBounds(70, 70, 770, 500);
        validate();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public String getPicture_address() {
        String address = null;
        try {
            FileInputStream outOne = new FileInputStream("picture_address.txt");
            ObjectInputStream outTwo = new ObjectInputStream(outOne);
            try {
                address = (String) outTwo.readObject();
            } catch (Exception ex) {
            }
            outTwo.close();
        } catch (IOException eee) {
        }
        if (address != null) {
            return address;
        } else {
            return "picture.jpg";
        }

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("更改图片背景")) {
            FileDialog dia = new FileDialog(this, "选定图片", FileDialog.LOAD);//新建一个文件选择对
            话框，用 dia 获得选择得到的信息；
            dia.setModal(true);//设置为模态对话框；
            dia.setVisible(true);

            //将取得的内容存入“picture_address.txt”文件中， 下次打开软件时还能记住上次的图片路径的选择；
            if ((dia.getDirectory() != null) && (dia.getFile() != null))
//如果得到的路径和文件名不为空；
            {
                try {
                    FileOutputStream inOne = new FileOutputStream("picture_address.txt");
                    ObjectOutputStream inTwo = new ObjectOutputStream(inOne);
                    inTwo.writeObject(dia.getDirectory() + dia.getFile());
                    inTwo.close();
                } catch (IOException ee) {
                }
                picturename = getPicture_address();
//从文件中读出显示图片的路径地址；
                calendarImage.setImageFile(new File(picturename));
//将获得路径传给图片， 显示该路径指定的图片
            }
        }
        if (e.getSource() == nextYear) {
            year++;
            showYear.setText("" + year);
            calendarMessage.setYear(year);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == previousYear) {
            year--;
            showYear.setText("" + year);
            calendarMessage.setYear(year);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == nextMonth) {
            month++;
            if (month > 12) month = 1;
            showMonth.setText("" + month);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == previousMonth) {
            month--;
            if (month < 1) month = 12;
            showMonth.setText("" + month);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == showYear) {
            String s = showYear.getText().trim();
            char a[] = s.toCharArray();
            boolean boo = false;
            for (int i = 0; i < a.length; i++) {
                if (!(Character.isDigit(a[i])))
                    boo = true;
            }
            if (boo == true)
                JOptionPane.showMessageDialog(this, "你输入了非法年份", "警告！ ", JOptionPane.WARNING_MESSAGE);
            else if (boo == false)
                year = Integer.parseInt(s);
            showYear.setText("" + year);
            calendarMessage.setYear(year);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == saveDailyRecord) {
            notePad.savefile(dir, year, month, day);
            doMark();
        } else if (e.getSource() == deleteDailyRecord) {
            notePad.deletefile(dir, year, month, day);
            doMark();
        } else if (e.getSource() == readDailyRecord) {
            notePad.readfile(dir, year, month, day);
            doMark();
        }
    }

    public void mousePressed(MouseEvent e) {
        JTextField text = (JTextField) e.getSource();
        String str = text.getText().trim();
        try {
            day = Integer.parseInt(str);
        } catch (NumberFormatException exp) {
        }
        calendarMessage.setDay(day);
        notePad.setMessage(year, month, day);
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void focusGained(FocusEvent e) {
        Component com = (Component) e.getSource();
        com.setBackground(Color.pink);
    }

    public void focusLost(FocusEvent e) {
        Component com = (Component) e.getSource();
        com.setBackground(backColor);
    }

    public void doMark() {
        for (int i = 0; i < showDay.length; i++) {
            showDay[i].removeAll();
            String str = showDay[i].getText().trim();
            try {
                int n = Integer.parseInt(str);
                if (isHaveDailyRecord(n) == true) {
                    JLabel mess = new JLabel("yes");
                    mess.setFont(new Font("TimesRoman", Font.PLAIN, 11));
                    mess.setForeground(Color.blue);
                    showDay[i].add(mess);
                }
            } catch (Exception exp) {
            }
        }
        calendarPad.repaint();
        calendarPad.validate();
    }

    public boolean isHaveDailyRecord(int n) {
        String key = "" + year + "" + month + "" + n;
        String[] dayFile = dir.list();
        boolean boo = false;
        for (int k = 0; k < dayFile.length; k++) {
            if (dayFile[k].equals(key + ".txt")) {
                boo = true;
                break;
            }
        }
        return boo;
    }

    public static void main(String args[]) {
        new CalendarWindow();
    }
}
import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;
        import java.util.*;
        import java.io.*;
        import java.awt.SplashScreen;

public class CalendarWindow extends JFrame implements ActionListener,
        MouseListener, FocusListener {
    int year, month, day;
    CalendarMessage calendarMessage;
    CalendarPad calendarPad;
    NotePad notePad;
    JTextField showYear, showMonth;
    JTextField showDay[];
    CalendarImage calendarImage;
    String picturename;//图像名称；
    String getPicture_address;
    Clock clock;
    JButton nextYear, previousYear, nextMonth, previousMonth;
    JButton saveDailyRecord, deleteDailyRecord, readDailyRecord;
    File dir;
    Color backColor = Color.white;

    public CalendarWindow() {
        dir = new File("./dailyRecord");
        dir.mkdir();
        showDay = new JTextField[42];
        for (int i = 0; i < showDay.length; i++) {
            showDay[i] = new JTextField();
            showDay[i].setBackground(backColor);
            showDay[i].setLayout(new GridLayout(3, 3));
            showDay[i].addMouseListener(this);
            showDay[i].addFocusListener(this);
        }
        calendarMessage = new CalendarMessage();
        calendarPad = new CalendarPad();
        notePad = new NotePad();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH) + 1;
        day = calendar.get(Calendar.DAY_OF_MONTH);
        calendarMessage.setYear(year);
        calendarMessage.setMonth(month);
        calendarMessage.setDay(day);
        calendarPad.setCalendarMessage(calendarMessage);
        calendarPad.setShowDayTextField(showDay);
        notePad.setMessage(year, month, day);
        calendarPad.showMonthCalendar();
        doMark();
        calendarImage = new CalendarImage();
        picturename = getPicture_address();//
        calendarImage.setImageFile(new File(picturename));
        JMenuBar menuBar = new JMenuBar();
        JMenu menusetting = new JMenu();
        JMenuItem changepicture = new JMenuItem();
        menusetting.setText("图像");//设置标题
        changepicture.setText("更改图片背景");//设置标题
        //添加菜单条上去；
        menusetting.add(changepicture);
        menuBar.add(menusetting);
        setJMenuBar(menuBar);
        //注册监听器
        changepicture.addActionListener(this);
        clock = new Clock();
        JSplitPane splitV1 = new
                JSplitPane(JSplitPane.VERTICAL_SPLIT, calendarPad, calendarImage);
        JSplitPane splitV2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, notePad, clock);
        JSplitPane splitH = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitV1, splitV2);
        add(splitH, BorderLayout.CENTER);
        showYear = new JTextField("" + year, 6);
        showYear.setFont(new Font("TimesRoman", Font.BOLD, 12));
        showYear.setHorizontalAlignment(JTextField.CENTER);
        showMonth = new JTextField("" + month, 4);
        showMonth.setFont(new Font("TimesRoman", Font.BOLD, 12));
        showMonth.setHorizontalAlignment(JTextField.CENTER);
        nextYear = new JButton("下年");
        previousYear = new JButton("上年");
        nextMonth = new JButton("下月");
        previousMonth = new JButton("上月");
        nextYear.addActionListener(this);
        previousYear.addActionListener(this);
        nextMonth.addActionListener(this);
        previousMonth.addActionListener(this);
        showYear.addActionListener(this);
        JPanel north = new JPanel();
        north.add(previousYear);
        north.add(showYear);
        north.add(nextYear);
        north.add(previousMonth);
        north.add(showMonth);
        north.add(nextMonth);
        add(north, BorderLayout.NORTH);
        saveDailyRecord = new JButton("保存日志");
        deleteDailyRecord = new JButton("删除日志");
        readDailyRecord = new JButton("读取日志");
        saveDailyRecord.addActionListener(this);
        deleteDailyRecord.addActionListener(this);
        readDailyRecord.addActionListener(this);
        JPanel pSouth = new JPanel();
        pSouth.add(saveDailyRecord);
        pSouth.add(deleteDailyRecord);
        pSouth.add(readDailyRecord);
        add(pSouth, BorderLayout.SOUTH);
        setVisible(true);
        setBounds(70, 70, 770, 500);
        validate();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public String getPicture_address() {
        String address = null;
        try {
            FileInputStream outOne = new FileInputStream("picture_address.txt");
            ObjectInputStream outTwo = new ObjectInputStream(outOne);
            try {
                address = (String) outTwo.readObject();
            } catch (Exception ex) {
            }
            outTwo.close();
        } catch (IOException eee) {
        }
        if (address != null) {
            return address;
        } else {
            return "picture.jpg";
        }

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("更改图片背景")) {
            FileDialog dia = new FileDialog(this, "选定图片", FileDialog.LOAD);//新建一个文件选择对
            话框，用 dia 获得选择得到的信息；
            dia.setModal(true);//设置为模态对话框；
            dia.setVisible(true);

            //将取得的内容存入“picture_address.txt”文件中， 下次打开软件时还能记住上次的图片路径的选择；
            if ((dia.getDirectory() != null) && (dia.getFile() != null))
//如果得到的路径和文件名不为空；
            {
                try {
                    FileOutputStream inOne = new FileOutputStream("picture_address.txt");
                    ObjectOutputStream inTwo = new ObjectOutputStream(inOne);
                    inTwo.writeObject(dia.getDirectory() + dia.getFile());
                    inTwo.close();
                } catch (IOException ee) {
                }
                picturename = getPicture_address();
//从文件中读出显示图片的路径地址；
                calendarImage.setImageFile(new File(picturename));
//将获得路径传给图片， 显示该路径指定的图片
            }
        }
        if (e.getSource() == nextYear) {
            year++;
            showYear.setText("" + year);
            calendarMessage.setYear(year);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == previousYear) {
            year--;
            showYear.setText("" + year);
            calendarMessage.setYear(year);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == nextMonth) {
            month++;
            if (month > 12) month = 1;
            showMonth.setText("" + month);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == previousMonth) {
            month--;
            if (month < 1) month = 12;
            showMonth.setText("" + month);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == showYear) {
            String s = showYear.getText().trim();
            char a[] = s.toCharArray();
            boolean boo = false;
            for (int i = 0; i < a.length; i++) {
                if (!(Character.isDigit(a[i])))
                    boo = true;
            }
            if (boo == true)
                JOptionPane.showMessageDialog(this, "你输入了非法年份", "警告！ ", JOptionPane.WARNING_MESSAGE);
            else if (boo == false)
                year = Integer.parseInt(s);
            showYear.setText("" + year);
            calendarMessage.setYear(year);
            calendarPad.setCalendarMessage(calendarMessage);
            calendarPad.showMonthCalendar();
            notePad.setMessage(year, month, day);
            doMark();
        } else if (e.getSource() == saveDailyRecord) {
            notePad.savefile(dir, year, month, day);
            doMark();
        } else if (e.getSource() == deleteDailyRecord) {
            notePad.deletefile(dir, year, month, day);
            doMark();
        } else if (e.getSource() == readDailyRecord) {
            notePad.readfile(dir, year, month, day);
            doMark();
        }
    }

    public void mousePressed(MouseEvent e) {
        JTextField text = (JTextField) e.getSource();
        String str = text.getText().trim();
        try {
            day = Integer.parseInt(str);
        } catch (NumberFormatException exp) {
        }
        calendarMessage.setDay(day);
        notePad.setMessage(year, month, day);
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void focusGained(FocusEvent e) {
        Component com = (Component) e.getSource();
        com.setBackground(Color.pink);
    }

    public void focusLost(FocusEvent e) {
        Component com = (Component) e.getSource();
        com.setBackground(backColor);
    }

    public void doMark() {
        for (int i = 0; i < showDay.length; i++) {
            showDay[i].removeAll();
            String str = showDay[i].getText().trim();
            try {
                int n = Integer.parseInt(str);
                if (isHaveDailyRecord(n) == true) {
                    JLabel mess = new JLabel("yes");
                    mess.setFont(new Font("TimesRoman", Font.PLAIN, 11));
                    mess.setForeground(Color.blue);
                    showDay[i].add(mess);
                }
            } catch (Exception exp) {
            }
        }
        calendarPad.repaint();
        calendarPad.validate();
    }

    public boolean isHaveDailyRecord(int n) {
        String key = "" + year + "" + month + "" + n;
        String[] dayFile = dir.list();
        boolean boo = false;
        for (int k = 0; k < dayFile.length; k++) {
            if (dayFile[k].equals(key + ".txt")) {
                boo = true;
                break;
            }
        }
        return boo;
    }

    public static void main(String args[]) {
        new CalendarWindow();
    }
}

import java.util.Calendar;

public class CalendarMessage {
    int year = -1, month = -1, day = -1;

    public void setYear(int year) {
        this.year = year;
    }

    public int getYear() {
        return year;
    }

    public void setMonth(int month) {
        if (month <= 12 && month >= 1)
            this.month = month;
        else
            this.month = 1;
    }

    public int getMonth() {
        return month;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getday() {
        return day;
    }

    public String[] getMonthCalendar() {
        String[] day = new String[42];
        Calendar rili = Calendar.getInstance();
        rili.set(year, month - 1, 1);//将日历翻到 year 年 month 月 1 日
        int 星期几 = rili.get(Calendar.DAY_OF_WEEK) - 1;
        int dayAmount = 0;
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
            dayAmount = 31;
        if (month == 4 || month == 6 || month == 9 || month == 11)
            dayAmount = 30;
        if (month == 2)
            if (((year % 4 == 0) && (year % 100 != 0)) || year % 400 == 0)
                dayAmount = 29;
            else
                dayAmount = 28;
        for (int i = 0; i < 星期几; i++)
            day[i] = " ";
        for (int i = 星期几, n = 1; i < 星期几 + dayAmount; i++) {
            day[i] = String.valueOf(n);
            n++;
        }
        for (int i = 星期几 + dayAmount; i < 42; i++)
            day[i] = " ";

        return day;
    }
}

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class CalendarPad extends JPanel {
    int year, month, day;
    CalendarMessage calendarMessage;
    JTextField[] showDay;
    JLabel title[];
    String[] 星期 = {"SUN 日", "MON 一", "TUE 二", "WED 三", "THU 四", "FRI 五", "SAT 六"};
    JPanel north, center;

    public CalendarPad() {
        setLayout(new BorderLayout());
        north = new JPanel();
        north.setLayout(new GridLayout(1, 7));
        center = new JPanel();
        center.setLayout(new GridLayout(6, 7));
        add(center, BorderLayout.CENTER);
        add(north, BorderLayout.NORTH);
        title = new JLabel[7];
        for (int j = 0; j < 7; j++) {
            title[j] = new JLabel();
            title[j].setFont(new Font("TimesRoman", Font.BOLD, 12));
            title[j].setText(星期[j]);
            title[j].setHorizontalAlignment(JLabel.CENTER);
            title[j].setBorder(BorderFactory.createRaisedBevelBorder());
            north.add(title[j]);
        }
        title[0].setForeground(Color.red);
        title[6].setForeground(Color.blue);
    }

    public void setShowDayTextField(JTextField[] text) {
        showDay = text;
        for (int i = 0; i < showDay.length; i++) {
            showDay[i].setFont(new Font("TimesRoman", Font.BOLD, 15));
            showDay[i].setHorizontalAlignment(JTextField.CENTER);
            showDay[i].setEditable(false);
            center.add(showDay[i]);
        }
    }

    public void setCalendarMessage(CalendarMessage calendarMessage) {
        this.calendarMessage = calendarMessage;
    }

    public void showMonthCalendar() {
        String[] a = calendarMessage.getMonthCalendar();
        for (int i = 0; i < 42; i++)
            showDay[i].setText(a[i]);
        validate();
    }
}

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;

class NotePad extends JPanel implements ActionListener, MouseListener, ItemListener {
    JPopupMenu popup;
    JMenuItem cut, copy, paste;
    JTextField ShowMessage, time;
    JTextArea ta;
    JPanel p1, p2, p3;
    Choice list1, list2;
    JButton btn;
    JLabel labl;
    String Size[] = {"10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36"};

    NotePad() {
        popup = new JPopupMenu();
        ShowMessage = new JTextField();
        ShowMessage.setEditable(false);
        ta = new JTextArea(5, 20);
        p1 = new JPanel();
        p2 = new JPanel();
        p3 = new JPanel();
        btn = new JButton("颜色");
        labl = new JLabel("事件发生时间（hh： mm）： ");
        time = new JTextField(10);
        list1 = new Choice();
        list2 = new Choice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String fontname[] = ge.getAvailableFontFamilyNames();
        for (int i = 0; i < fontname.length; i++) {
            list1.add(fontname[i]);
        }
        for (int i = 0; i < Size.length; i++) {
            list2.add(Size[i]);
        }
        cut = new JMenuItem("剪切");
        cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
        copy = new JMenuItem("复制");
        copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
        paste = new JMenuItem("粘贴");
        paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
        popup.add(cut);
        popup.add(copy);
        popup.add(paste);
        p1.add(list1);
        p1.add(list2);
        //p1.add(btn);
        p3.add(labl);
        p3.add(time);
        setLayout(new BorderLayout());
        add(ShowMessage, BorderLayout.NORTH);
        p2.setLayout(new BorderLayout());
        p2.add(new JScrollPane(ta), BorderLayout.CENTER);
        //p2.add(p3,BorderLayout.SOUTH);
        add(p2, BorderLayout.CENTER);
        add(p1, BorderLayout.SOUTH);
        setBounds(0, 0, 600, 600);
        setVisible(true);
        btn.addActionListener(this);
        list1.addItemListener(this);
        list2.addItemListener(this);
        cut.addActionListener(this);
        copy.addActionListener(this);
        paste.addActionListener(this);
        ta.addMouseListener(this);
    }

    public void setMessage(int year, int month, int day) {
        ShowMessage.setText(year + "年" + month + "月" + day + "日");
        ShowMessage.setForeground(Color.blue);
        ShowMessage.setFont(new Font("宋体", Font.BOLD, 15));
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == cut) {
            cut();
        }
        if (e.getSource() == copy) {
            copy();
        }
        if (e.getSource() == paste) {
            paste();
        }
        if (e.getSource() == btn) {
            Color newColor = JColorChooser.showDialog(this, "选择颜色", ta.getForeground());
            if (newColor != null) {
                ta.setForeground(newColor);
            }
        }
    }

    public void itemStateChanged(ItemEvent e) {
        String n1 = list2.getSelectedItem();
        String name = list1.getSelectedItem();
        int n2 = Integer.parseInt(n1);
        Font f = new Font(name, Font.PLAIN, n2);
        ta.setFont(f);
    }

    public void mouseReleased(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON3) {
            popup.show(ta, e.getX(), e.getY());
        }
        if (e.getButton() == MouseEvent.BUTTON1) {
            popup.setVisible(false);
        }
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void cut() {
        ta.cut();
        popup.setVisible(false);
    }

    public void copy() {
        ta.copy();
        popup.setVisible(false);
    }

    public void paste() {
        ta.paste();
        popup.setVisible(false);
    }

    public void savefile(File dir, int year, int month, int day) {
        String dailyRecord = time.getText() + "#" + ta.getText() + "#";
        String fileName = "" + year + "" + month + "" + day + ".txt";
        String key = "" + year + "" + month + "" + day;
        String dialyFile[] = dir.list();
        boolean b = false;
        for (int i = 0; i < dialyFile.length; i++) {
            if (dialyFile[i].startsWith(key)) {
                b = true;
                break;
            }
        }
        if (b) {
            int n = JOptionPane.showConfirmDialog(this, "" + year + "年" + month + "月 " + day + "日 " + "
                    已经有日志存在， 是否添加日志？ "," 确认对话框",JOptionPane.YES_NO_OPTION);
            if (n == JOptionPane.YES_OPTION) {
                try {
                    File file = new File(dir, fileName);
                    RandomAccessFile out = new RandomAccessFile(file, "rw");
                    long end = out.length();
                    byte[] bb = dailyRecord.getBytes();
                    out.seek(end);
                    out.write(bb);
                    out.close();
                } catch (IOException e) {
                }
                ta.setText("");
            } else {
                ta.setText("");
            }
        } else {
            try {
                File file = new File(dir, fileName);
                FileWriter fw = new FileWriter(file);
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(dailyRecord);
                bw.close();
                fw.close();
            } catch (IOException e) {
            }
            JOptionPane.showMessageDialog(this, " 添 加 日 志 成 功 ", " 消 息 对 话 框
                    ",JOptionPane.INFORMATION_MESSAGE);
                    ta.setText("");
            time.setText("");
        }
    }

    public void deletefile(File dir, int year, int month, int day) {
        String key = "" + year + "" + month + "" + day;
        String dialyFile[] = dir.list();
        boolean b = false;
        for (int i = 0; i < dialyFile.length; i++) {
            if (dialyFile[i].startsWith(key)) {
                b = true;
                break;
            }
        }
        if (b) {
            int n = JOptionPane.showConfirmDialog(this, " 是 否 删 除 " + year + " 年 " + month + " 月
                    "+day+" 日的日志？ "," 确认对话框",JOptionPane.YES_NO_OPTION);
            if (n == JOptionPane.YES_OPTION) {
                try {
                    String fileName = "" + year + "" + month + "" + day + ".txt";
                    File file = new File(dir, fileName);
                    file.delete();
                } catch (Exception e) {
                }
                ta.setText("");
            }
        } else {
            JOptionPane.showMessageDialog(this, "" + year + "年" + month + "月 " + day + "日 无日 志！
                    "," 消息对话框",JOptionPane.INFORMATION_MESSAGE);
        }
    }

    public void readfile(File dir, int year, int month, int day) {
        String fileName = "" + year + "" + month + "" + day + ".txt";
        String key = "" + year + "" + month + "" + day;
        String dialyFile[] = dir.list();
        boolean b = false;
        for (int i = 0; i < dialyFile.length; i++) {
            if (dialyFile[i].startsWith(key)) {
                b = true;
                break;
            }
        }
        if (b) {
            ta.setText("");
            time.setText("");
            try {
                File file = new File(dir, fileName);
                FileReader inOne = new FileReader(file);
                BufferedReader inTwo = new BufferedReader(inOne);
                String s;
                while ((s = inTwo.readLine()) != null) {
                    ta.append(s + "\n");
                }
                inOne.close();
                inTwo.close();
            } catch (IOException e) {
            }
        } else {
            JOptionPane.showMessageDialog(this, "" + year + "年" + month + "月 " + day + "日 无日 志！
                    "," 消息对话框",JOptionPane.INFORMATION_MESSAGE);
        }
    }
}

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import java.util.*;
import java.net.*;
import java.applet.*;
import java.io.*;

public class Clock extends JPanel implements ActionListener {
    Date date;
    javax.swing.Timer secondTime;
    int hour, minute, second;
    Line2D secondLine, minuteLine, hourLine;
    int a, b, c, width, height;
    double[] pointSX = new double[60], //用来表示秒针端点坐标的数组
            pointSY = new double[60],
            pointMX = new double[60], //用来表示分针端点坐标的数组
            pointMY = new double[60],
            pointHX = new double[60], //用来表示时针端点坐标的数组
            pointHY = new double[60];

    Clock() {
        setBackground(Color.cyan);
        initPoint();
        secondTime = new javax.swing.Timer(1000, this);
        secondLine = new Line2D.Double(0, 0, 0, 0);
        minuteLine = new Line2D.Double(0, 0, 0, 0);
        hourLine = new Line2D.Double(0, 0, 0, 0);
        secondTime.start(); //秒针开始计时
    }

    private void initPoint() {
        width = getBounds().width;
        height = getBounds().height;
        pointSX[0] = 0; //12 点秒针位置
        pointSY[0] = -height / 2 * 5 / 6;
        pointMX[0] = 0; //12 点分针位置
        pointMY[0] = -(height / 2 * 4 / 5);
        pointHX[0] = 0; //12 点时针位置
        pointHY[0] = -(height / 2 * 2 / 3);
        double angle = 6 * Math.PI / 180; //刻度为 6 度
        for (int i = 0; i < 59; i++) { //计算数组中的坐标
            pointSX[i + 1] = pointSX[i] * Math.cos(angle) - Math.sin(angle) * pointSY[i];
            pointSY[i + 1] = pointSY[i] * Math.cos(angle) + pointSX[i] * Math.sin(angle);
            pointMX[i + 1] = pointMX[i] * Math.cos(angle) - Math.sin(angle) * pointMY[i];
            pointMY[i + 1] = pointMY[i] * Math.cos(angle) + pointMX[i] * Math.sin(angle);
            pointHX[i + 1] = pointHX[i] * Math.cos(angle) - Math.sin(angle) * pointHY[i];
            pointHY[i + 1] = pointHY[i] * Math.cos(angle) + pointHX[i] * Math.sin(angle);
        }
        for (int i = 0; i < 60; i++) {
            pointSX[i] = pointSX[i] + width / 2; //坐标平移
            pointSY[i] = pointSY[i] + height / 2;
            pointMX[i] = pointMX[i] + width / 2; //坐标平移
            pointMY[i] = pointMY[i] + height / 2;
            pointHX[i] = pointHX[i] + width / 2; //坐标平移
            pointHY[i] = pointHY[i] + height / 2;
        }
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        initPoint();
        for (int i = 0; i < 60; i++) { //绘制表盘上的小刻度和大刻度
            int m = (int) pointSX[i];
            int n = (int) pointSY[i];
            if (i % 5 == 0) {
                if (i == 0 || i == 15 || i == 30 || i == 45) {
                    int k = 10;
                    g.setColor(Color.orange);
                    g.fillOval(m - k / 2, n - k / 2, k, k);
                } else {
                    int k = 7;
                    g.setColor(Color.orange);
                    g.fillOval(m - k / 2, n - k / 2, k, k);
                }
            } else {
                int k = 2;
                g.setColor(Color.black);
                g.fillOval(m - k / 2, n - k / 2, k, k);
            }
        }
        g.fillOval(width / 2 - 5, height / 2 - 5, 10, 10); //钟表中心的实心圆
        Graphics2D g_2d = (Graphics2D) g;
        g_2d.setColor(Color.red);
        g_2d.draw(secondLine);
        BasicStroke bs =
                new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
        g_2d.setStroke(bs);
        g_2d.setColor(Color.blue);
        g_2d.draw(minuteLine);
        bs = new BasicStroke(4f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
        g_2d.setStroke(bs);
        g_2d.setColor(Color.orange);
        g_2d.draw(hourLine);
        if ((minute == 59) && (second == 50)) {
//播放指定音频；
            try {
                File f = new File("报时.wav");//音频文件；
                URI uri = f.toURI();
                URL url = uri.toURL();
                AudioClip aau;
                aau = Applet.newAudioClip(url); //创建 AudioClip 对象；
                aau.play();//播放音频；
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == secondTime) {
            date = new Date();
            String s = date.toString();
            hour = Integer.parseInt(s.substring(11, 13));
            minute = Integer.parseInt(s.substring(14, 16));
            second = Integer.parseInt(s.substring(17, 19)); //获取时间中的秒
            int h = hour % 12;
            a = second; //秒针端点的坐标
            b = minute; //分针端点的坐标
            c = h * 5 + minute / 12; //时针端点的坐标
            secondLine.setLine(width / 2, height / 2, (int) pointSX[a], (int) pointSY[a]);
            minuteLine.setLine(width / 2, height / 2, (int) pointMX[b], (int) pointMY[b]);
            hourLine.setLine(width / 2, height / 2, (int) pointHX[c], (int) pointHY[c]);
            repaint();
        }
    }
}
